from pprint import pprint
from paddleocr import PaddleOCR
import gradio as gr

ocr = PaddleOCR(use_angle_cls=True, lang="ch")


def process(image):
    result = ocr.ocr(image)

    output_text = ""  # 初始化输出文本变量
    for sublist in result:
        for line in sublist:
            text = line[1][0]  # 提取文本
            output_text += text + "\n"  # 将文本追加到输出文本变量，并添加换行符
            pprint(output_text)
    return output_text


iface = gr.Interface(fn=process, inputs="image", outputs="text", title="图片OCR提取文字")
iface.launch()
